//声明类
class Bus {
  constructor() {
    //定义事件总线对象
    this.eventList = {}
  }
  //监听，或者说是发布
  $on(event, fn) {
    let eventList = this.eventList[event]
    eventList ? eventList.push(fn) : (this.eventList[event] = [fn])
  }
  //触发，订阅
  $emit(name, data) {
    this.eventList[name] &&
      this.eventList[name].forEach((fn) => {
        fn(data)
      })
  }
  $off(name) {
    delete this.eventList[name]
  }
}

export default new Bus()
